from PyQt6.QtWidgets import QDialog
from ui.Dialog_ui import Ui_Dialog
from PyQt6.QtCore import pyqtSlot, Qt, pyqtSignal
from controller.MainController import MainController

class MyDialog(Ui_Dialog, QDialog):
    update_btn_signal = pyqtSignal(str, int)
    def __init__(self, parent=None):
        super().__init__(parent)
        self.setupUi(self)
        self.index = -1

    def setIndex(self, index):
        self.index = index


    
    @pyqtSlot()
    def on_dialogSubmitBtn_clicked(self):
        text = self.dialogPlainTextEdit.toPlainText()
        self.dialogPlainTextEdit.clear()
        self.update_btn_signal.emit(text, self.index)
        self.hide()
   

    @pyqtSlot()
    def on_dialogPlainTextEdit_textChanged(self):
        text = self.dialogPlainTextEdit.toPlainText()
        if "\n" in text:
            text = text.replace("\n", "")
            self.dialogPlainTextEdit.clear()
            self.update_btn_signal.emit(text, self.index)
